VERSION 5.00
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
Object = "{B3FB64BF-91F9-11D7-A482-0008A14158BC}#2.22#0"; "ITGControls.ocx"
Begin VB.Form frmAPList 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "Payables Details"
   ClientHeight    =   5325
   ClientLeft      =   45
   ClientTop       =   330
   ClientWidth     =   8565
   BeginProperty Font 
      Name            =   "Tahoma"
      Size            =   8.25
      Charset         =   0
      Weight          =   400
      Underline       =   0   'False
      Italic          =   0   'False
      Strikethrough   =   0   'False
   EndProperty
   Icon            =   "frmAPList.frx":0000
   KeyPreview      =   -1  'True
   LinkTopic       =   "Form1"
   LockControls    =   -1  'True
   MaxButton       =   0   'False
   ScaleHeight     =   5325
   ScaleWidth      =   8565
   StartUpPosition =   1  'CenterOwner
   Begin VB.Frame Frame4 
      Caption         =   "Details"
      Height          =   2505
      Left            =   60
      TabIndex        =   9
      Top             =   2325
      Width           =   8430
      Begin MSComctlLib.ListView lvwList 
         Height          =   2130
         Left            =   120
         TabIndex        =   1
         Top             =   255
         Width           =   8190
         _ExtentX        =   14446
         _ExtentY        =   3757
         View            =   3
         Sorted          =   -1  'True
         LabelWrap       =   -1  'True
         HideSelection   =   -1  'True
         FullRowSelect   =   -1  'True
         GridLines       =   -1  'True
         HotTracking     =   -1  'True
         _Version        =   393217
         ForeColor       =   -2147483640
         BackColor       =   -2147483643
         BorderStyle     =   1
         Appearance      =   0
         NumItems        =   0
      End
   End
   Begin VB.Frame Frame1 
      Height          =   2205
      Left            =   60
      TabIndex        =   4
      Top             =   60
      Width           =   8430
      Begin MSComctlLib.ListView lvwRef 
         Height          =   1845
         Left            =   105
         TabIndex        =   0
         Top             =   225
         Width           =   1635
         _ExtentX        =   2884
         _ExtentY        =   3254
         View            =   3
         LabelWrap       =   -1  'True
         HideSelection   =   -1  'True
         FullRowSelect   =   -1  'True
         GridLines       =   -1  'True
         HotTracking     =   -1  'True
         _Version        =   393217
         ForeColor       =   -2147483640
         BackColor       =   -2147483643
         BorderStyle     =   1
         Appearance      =   0
         NumItems        =   1
         BeginProperty ColumnHeader(1) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
            Text            =   "Reference No."
            Object.Width           =   2646
         EndProperty
      End
      Begin ITGControls.ITGTextBox txtCode 
         Height          =   285
         Left            =   2055
         TabIndex        =   5
         Top             =   240
         Width           =   2265
         _ExtentX        =   3784
         _ExtentY        =   503
         SendKeysTab     =   -1  'True
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         AllCaps         =   -1  'True
         Mandatory       =   -1  'True
         Locked          =   -1  'True
         Label           =   "Supplier"
         BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         LabelWidth      =   1000
         TextBoxWidth    =   1205
      End
      Begin ITGControls.ITGDateBox dtbDate 
         Height          =   285
         Left            =   3060
         TabIndex        =   6
         Tag             =   "Order Date"
         Top             =   960
         Width           =   1275
         _ExtentX        =   2249
         _ExtentY        =   503
         Enabled         =   0   'False
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Text            =   ""
         SendKeysTab     =   -1  'True
         Mandatory       =   -1  'True
         DatePicker      =   0   'False
      End
      Begin ITGControls.ITGLabel ITGLabel4 
         Height          =   285
         Left            =   2100
         TabIndex        =   7
         Top             =   960
         Width           =   915
         _ExtentX        =   1614
         _ExtentY        =   503
         Caption         =   "DR Date"
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
      End
      Begin ITGControls.ITGTextBox txtName 
         Height          =   285
         Left            =   4365
         TabIndex        =   8
         Top             =   240
         Width           =   3930
         _ExtentX        =   6826
         _ExtentY        =   503
         SendKeysTab     =   -1  'True
         BackColor       =   14737632
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Locked          =   -1  'True
         Label           =   "ITGtext"
         BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         LabelWidth      =   0
         TextBoxWidth    =   3870
      End
      Begin ITGControls.ITGTextBox txtDesc 
         Height          =   285
         Left            =   2055
         TabIndex        =   12
         Top             =   600
         Width           =   6240
         _ExtentX        =   10795
         _ExtentY        =   503
         SendKeysTab     =   -1  'True
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         AllCaps         =   -1  'True
         Mandatory       =   -1  'True
         Locked          =   -1  'True
         Label           =   "Description"
         BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         LabelWidth      =   1000
         TextBoxWidth    =   5180
      End
   End
   Begin ITGControls.ITGCommandButton cmdCancel 
      Height          =   345
      Left            =   7290
      TabIndex        =   3
      Top             =   4920
      Width           =   1200
      _ExtentX        =   2117
      _ExtentY        =   609
      BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "Tahoma"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Caption         =   "&Cancel"
   End
   Begin ITGControls.ITGCommandButton cmdOK 
      Height          =   345
      Left            =   6030
      TabIndex        =   2
      Top             =   4920
      Width           =   1200
      _ExtentX        =   2117
      _ExtentY        =   609
      BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "Tahoma"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Caption         =   "&OK"
   End
   Begin ITGControls.ITGCommandButton cmdCAll 
      Height          =   345
      Left            =   60
      TabIndex        =   10
      Top             =   4920
      Visible         =   0   'False
      Width           =   1200
      _ExtentX        =   2117
      _ExtentY        =   609
      BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "Tahoma"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Caption         =   "Check All"
   End
   Begin ITGControls.ITGCommandButton cmdUCAll 
      Height          =   345
      Left            =   1320
      TabIndex        =   11
      Top             =   4920
      Visible         =   0   'False
      Width           =   1200
      _ExtentX        =   2117
      _ExtentY        =   609
      BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "Tahoma"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Caption         =   "Uncheck All"
   End
End
Attribute VB_Name = "frmAPList"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Enum eAPType
    Payables
End Enum

Public mType As eAPType
Public mRefPK As String


Private connList As New ADODB.Connection

Private Sub cmdCAll_Click()
    If lvwList.ListItems.Count = 0 Then Exit Sub
    For i = 1 To lvwList.ListItems.Count
        lvwList.ListItems(i).Checked = True
    Next i
End Sub

Private Sub cmdCancel_Click()
    Unload Me
    mRefPK = ""
    Set frmAPList = Nothing
End Sub

Private Sub cmdOK_Click()
    Unload Me
End Sub

Private Sub cmdUCAll_Click()
    If lvwList.ListItems.Count = 0 Then Exit Sub
    For i = 1 To lvwList.ListItems.Count
        lvwList.ListItems(i).Checked = False
    Next i
End Sub

Private Sub Form_KeyPress(KeyAscii As Integer)
    If KeyAscii = vbKeyEscape Then
        Unload Me
        Set frmAPList = Nothing
    End If
End Sub

Private Sub Form_Load()

    SetupListView
    
    Select Case mType
        Case Payables
            Reference "cTranNo", "V_ForPayables", "cCode = '" & RepName & "' AND lApproved = 1 "
            Caption = "Request For Payment Detail List [Reference: Payable Setup]"
    End Select
    If lvwRef.ListItems.Count <> 0 Then lvwRef_ItemClick lvwRef.ListItems(lvwRef.SelectedItem.Index)
End Sub

'Reference list
Sub Reference(RefField As String, RefTable As String, Optional Condition As String)
    
    If Trim(Condition) <> "" Then Condition = " AND " & Condition
    
    sSQL = "SELECT DISTINCT " & Trim(RefField) & " AS cRefNo FROM " & Trim(RefTable) & " WHERE cCompanyID = '" & COID & "'" & Condition
    OpenNewConnection connList
    Set rs = New Recordset
    rs.Open sSQL, connList, adOpenForwardOnly, adLockReadOnly
    lvwRef.ListItems.Clear
    Do Until rs.EOF
        Set itmX = lvwRef.ListItems.Add(, , Trim(rs!cRefNo))
    rs.MoveNext
    Loop
    Set rs = Nothing

End Sub

Sub ListQuery(RefPK As String)

    Select Case mType
        Case DR
            sSQL = "SELECT A.cCode AS RefCode, B.cName AS RefName, dDate AS RefDate, A.cDesc as cRemarks " & _
                    "FROM V_ForPayables A left outer join CLIENT_SUPPLIER_NT B on A.cCode = B.cCode and A.cCompanyID = B.cCompanyID " & _
                    "WHERE cTranNo = '" & Trim(RefPK) & "' AND A.cCompanyID = '" & COID & "'"
            ListHeader
            sSQL = "SELECT cAcctNo, cTitle, cRemarks, nDebit, nCredit FROM PAYABLES_ACCOUNT " & _
                    "WHERE cTranNo = '" & Trim(RefPK) & "' AND cCompanyID = '" & COID & "'"
            ListDetail
    End Select

End Sub

'Header details
Sub ListHeader()
    OpenNewConnection connList
    Set rs = New Recordset
    rs.Open sSQL, connList, adOpenForwardOnly, adLockReadOnly
    If rs.RecordCount <> 0 Then
        txtCode = rs!RefCode & ""
        txtName = rs!refname & ""
        txtDesc = rs!cRemarks & ""
        dtbDate.Text = Format(rs!RefDate, "MM/dd/yyyy") & ""
    End If
    Set rs = Nothing
End Sub

'Item details
Sub ListDetail()
    Set rs = New Recordset
    DoEvents
    
    OpenNewConnection connList
    rs.Open sSQL, connList, adOpenForwardOnly, adLockReadOnly
    lvwList.ListItems.Clear
    lvwList.Visible = False
    
    Select Case mType
        Case Payables
            Do Until rs.EOF
                Set itmX = lvwList.ListItems.Add(, , Trim(rs!cAcctNo) & "")
                itmX.SubItems(1) = Trim(rs!cTitle) & ""
                itmX.SubItems(2) = Trim(rs!cRemarks) & ""
                itmX.SubItems(3) = Format(rs!nDebit, "###,##0.#0") & ""
                itmX.SubItems(4) = Format(rs!nCredit, "###,##0.#0") & ""
                rs.MoveNext
            Loop
    End Select
    
    lvwList.Visible = True
    Set rs = Nothing
End Sub

Private Sub Form_Unload(Cancel As Integer)
    Set connList = Nothing
End Sub

Private Sub lvwList_GotFocus()
    If lvwList.ListItems.Count <> 0 Then lvwList_ItemClick lvwList.ListItems(lvwList.SelectedItem.Index)
End Sub

Private Sub lvwList_ItemClick(ByVal Item As MSComctlLib.ListItem)
    If lvwList.ListItems.Count = 0 Then Exit Sub
End Sub

Private Sub lvwList_KeyPress(KeyAscii As Integer)
    If KeyAscii = 13 Then
        If lvwList.SelectedItem.Checked = True Then
            lvwList.SelectedItem.Checked = False
        Else: lvwList.SelectedItem.Checked = True
        End If
    End If
End Sub

Private Sub lvwRef_ItemClick(ByVal Item As MSComctlLib.ListItem)
    If lvwRef.ListItems.Count = 0 Then Exit Sub
    mRefPK = Trim(lvwRef.SelectedItem)
    ListQuery (Trim(lvwRef.SelectedItem))
End Sub

Private Sub lvwRef_KeyPress(KeyAscii As Integer)
    If lvwRef.ListItems.Count = 0 Then Exit Sub
    If KeyAscii = 13 Then lvwRef_ItemClick lvwRef.ListItems(lvwRef.SelectedItem.Index)
End Sub

Private Sub SetupListView()
    With lvwList
        Select Case mType
            Case Payables
                Set itmX = .ColumnHeaders.Add(, , "Accnt No.", 1200)
                Set itmX = .ColumnHeaders.Add(, , "Title", 3000)
                Set itmX = .ColumnHeaders.Add(, , "Remarks", 3000)
                Set itmX = .ColumnHeaders.Add(, , "Debit", 1200, 1)
                Set itmX = .ColumnHeaders.Add(, , "Credit", 1200, 1)
        End Select
    End With
End Sub
